package com.atguigu.gmall.task.scheduled;

import com.atguigu.gmall.common.constant.MqConst;
import com.atguigu.gmall.common.service.RabbitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author mqx
 * @date 2020-10-27 15:56:46
 */
@Component
@EnableScheduling   //  开启定时任务
public class ScheduledTask {

    @Autowired
    private RabbitService rabbitService;

    //  编写一个定时任务：分时日月周年
//    @Scheduled(cron = "0 0 1 * * ?")
//    public void test1(){
//        System.out.println("定时任务。。。");
//    }
    //  每隔三十秒执行一次！ 每天夜里凌晨1点！
    @Scheduled(cron = "0/10 * * * * ?")
    public void test1(){
        //  System.out.println("定时任务。。。"+Thread.currentThread().getName());
        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK,MqConst.ROUTING_TASK_1,"来人了，开始接客了.");

    }
    //  清空缓存数据
    @Scheduled(cron = "0 0 18 * * ?")
    public void task18() {
        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK,MqConst.ROUTING_TASK_18,"");
    }

}
